import requests
import random
import time


# 时间戳转换成日期格式
def timestamp_datetime(value):

    timestamp_milliseconds = value / 1000  # 将毫秒转换为秒
    # 转换为时间元组
    time_tuple = time.localtime(timestamp_milliseconds)
    # 格式化时间
    formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", time_tuple)
    print(f"发布时间：{formatted_time}")

# 从代理ip池中随机获取一个ip
def get_ip():
    # 从txt文件中读取所有行
    with open('IP_proxy//ip.txt', 'r') as file:
        lines = file.readlines()

        # 从所有行中随机选择一行
    proxy = random.choice(lines)

    kv={'User-Agent':'Mozilla/5.0 '}
    proxies = {
            'http': proxy

        }
    return proxies

url = f"https://24365.ncss.cn/student/jobs/jobslist/ajax/?jobType=03&areaCode=&jobName=&monthPay=&industrySectors=000103%2C&property=&categoryCode=&memberLevel=&recruitType=&offset=1&limit=10&keyUnits=&degreeCode=&sourcesName=0&sources"
kv = {'user-agent': 'Mozilla/5.0'}
proxies = get_ip()
r=requests.get(url,headers=kv,proxies=proxies)
r.encoding='utf-8'
data=r.json()
offier_data=data.get('data').get('list')
for i in offier_data:
    print(f"工作名称：{i.get('jobName')}")
    print(f"月薪高:{i.get('highMonthPay')}")
    value=i.get('publishDate')
    timestamp_datetime(value)
    print(f"最低薪资：{i.get('lowMonthPay')}")
    print(f"招聘人数：{i.get('headCount')}")
    print(f"学历：{i.get('degreeName')}")
    print(f"招聘单位：{i.get('recName')}")
    print(f"地点：{i.get('areaCodeName')}")
    print(f"福利待遇：{i.get('recTags')}")
    print(f"专业要求：{i.get('major')}")
    print(f"企业类型：{i.get('recProperty')}")
    print()